@include('Admin.public.head')

<body>
@include('Admin.public.menu')
<link rel="stylesheet" href="{{ URL::asset('js/upload/css/uploadImg.css') }}">
<link rel="stylesheet" href="{{ URL::asset('js/admin/layui/css/layui.css') }}">
<link rel="stylesheet" href="{{ URL::asset('css/fonts/font-awesome.min.css') }}">
<style>
	.imgs {
		position: relative;
		width: 150px;
		height: 150px;
	}
	#demo1 {
		width: 100%;
		height: 100%;
		margin: 0 10px 10px 0;
	}
	.closed {
		display: block;
		background: #f5f5f5;
		position: absolute;
		right: -6px;
		top: -6px;
		font-size: 12px;
		padding: 5px;
		border-radius: 50%;
	}
	.closed:hover {
		cursor: pointer;
	} 
	#demo3 {
		height: 100%;
		display: flex;
		justify-content: flex-start;
		flex-wrap: wrap;
	}
	#demo3 .del {
		margin: 10px;
	}
	.updsa-imgs {
		width: 100%;
		height: 100%;
	}
	.upImgs {
		position: relative;
		width: 150px;
		height: 150px;
	}
</style>
<div class=" admin-content">
    <div class="daohang">

    </div>
    <div class="admin-biaogelist" id="app">
        <div class="listbiaoti am-cf">
            <ul class="am-icon-flag on"> 添加商品</ul>
            <dl class="am-icon-home" style="float: right;"> 当前位置： 首页 > <a href="#">商品列表</a></dl>
        </div>
        <div class="fbneirong">
            <form class="am-form">
                <div class="am-form-group am-cf">
                    <div class="zuo">商品名称：</div>
                    <div class="you" style="max-width: 300px;">
                    <input type="text" v-model="goods.goodsname" class="am-input-sm" id="doc-ipt-email-1"
                               placeholder="请输入商品名称">
                    </div>
                </div>
                <div class="am-form-group am-cf">
                    <div class="zuo">商品一级分类：</div>
                    <div class="you" style="max-width: 300px;">
                        {{--<select type="password" class="am-input-sm" id="doc-ipt-pwd-1" placeholder="请输入关键词">--}}
                        <select name="" class="am-input-sm" v-model="goods.cid" id="doc-ipt-pwd-1"
                                @change="two_tid(goods.cid)">
                            <option value="">请选择一级分类</option>
                            <option v-for="val in categoryList" :value="val.id">@{{ val.name }}</option>
                        </select>
                    </div>
                </div>
                <div class="am-form-group am-cf" id="two_cid_li">
                    <div class="zuo">商品二级分类：</div>
                    <div class="you" style="max-width: 300px;">
                    <select name="" class="am-input-sm" v-model="goods.two_tid" id="doc-ipt-pwd-1">
                            <option value="">请选择二级分类</option>
                            <option v-for="val in categoryLists" :value="val.id">@{{ val.name }}</option>
                        </select>
                    </div>
                </div>

				
				<div class="am-form-group am-cf" v-show="goods.cid == 1" >
				    <div class="zuo">报单会员等级：</div>
				    <div class="you" style="max-width: 300px;">
				    <select name="" class="am-input-sm" v-model="goods.level" id="sel-platform">
				            <option v-for="val in memberLevel" :value="val.id">@{{ val.vip_name }}</option>
				        </select>
				    </div>
				</div>
                <div class="am-form-group am-cf">
                    <div class="zuo">原价：</div>
                    <div class="you" style="max-width: 300px;">
                    <input type="text" v-model="goods.originalprice" class="am-input-sm" id="doc-ipt-email-1"
                               placeholder="请输入原价">
                    </div>
                </div>
                <div class="am-form-group am-cf" >
                    <div class="zuo">现价：</div>
                    <div class="you" style="max-width: 300px;">
                        <input type="text" v-model="goods.rulingprice" class="am-input-sm" id="doc-ipt-email-1"
                               placeholder="请输入现价">
                    </div>
                </div>
{{--                <div class="am-form-group am-cf">--}}
{{--                    <div class="zuo">e+积分(可不填)：</div>--}}
{{--                    <div class="you" style="max-width: 300px;">--}}
{{--                        <input type="text" v-model="goods.is_explosive" class="am-input-sm" id="doc-ipt-email-1"--}}
{{--                               placeholder="请输入e+积分分值">--}}
{{--                    </div>--}}
{{--                </div>--}}
                 <div class="am-form-group am-cf">
                    <div class="zuo">分佣PV值：</div>
                    <div class="you" style="max-width: 300px;">
                    <input type="text" v-model="goods.pk_integral" class="am-input-sm" id="doc-ipt-email-1"
                               placeholder="请输入分佣PV值">
                    </div>
                </div>
{{--                <div class="am-form-group am-cf" v-show="goods.cid == 7">--}}
{{--                    <div class="zuo">是否复投产品</div>--}}
{{--                    <div class="you" style="max-width: 300px;">--}}
{{--                        <input type="text" v-model="goods.read_integral" class="am-input-sm" id="doc-ipt-email-1"--}}
{{--                               placeholder="阅读积分抵扣占比">--}}
{{--                    </div>--}}
{{--                </div>--}}
				
{{--				<div class="am-form-group am-cf" v-show="goods.cid == 7">--}}
{{--				    <div class="zuo">阅读积分抵扣占比：%</div>--}}
{{--				    <div class="you" style="max-width: 300px;">--}}
{{--				    <input type="text" v-model="goods.read_integral" class="am-input-sm" id="doc-ipt-email-1"--}}
{{--				               placeholder="阅读积分抵扣占比">--}}
{{--				    </div>--}}
{{--				</div>--}}
				
                <div class="am-form-group am-cf">
                    <div class="zuo">起购数量：</div>
                    <div class="you" style="max-width: 300px;">
                    <input type="text" v-model="goods.purchase_num"  class="am-input-sm" id="doc-ipt-email-1"
                               placeholder="请输入起购数量">
                    </div>
                </div>

                <div class="am-form-group am-cf">
                    <div class="zuo">库存：</div>
                    <div class="you" style="max-width: 300px;">
                    <input type="number" v-model="goods.total" min="0" class="am-input-sm" id="doc-ipt-email-1"
                               placeholder="请输入排序">
                    </div>
                </div>
                <div class="am-form-group am-cf">
                    <div class="zuo">排序：</div>
                    <div class="you" style="max-width: 300px;">
                        <input type="number" v-model="goods.sorting" min="0" class="am-input-sm" id="doc-ipt-email-1"
                               placeholder="请输入库存">
                    </div>
                </div>
                <div class="am-form-group am-cf"  v-show="goods.cid == 3">
                    <div class="zuo">是否复投产品：</div>
                    <div class="you" style="margin-top: 3px;">
                        <label class="am-checkbox-inline">
                            <input type="radio" value="1" v-model="goods.is_throw" data-am-ucheck=""
                                   class="am-ucheck-radio">
                            <span class="am-ucheck-icons"><i class="am-icon-unchecked"></i><i
                                        class="am-icon-checked"></i></span>是
                        </label>
                        <label class="am-checkbox-inline">
                            <input type="radio" value="0" v-model="goods.is_throw" data-am-ucheck=""
                                   class="am-ucheck-radio">
                            <span class="am-ucheck-icons"><i class="am-icon-unchecked"></i><i
                                        class="am-icon-checked"></i></span>否
                        </label>
                    </div>
                </div>
                <div class="am-form-group am-cf">
                    <div class="zuo">状态：</div>
                    <div class="you" style="margin-top: 3px;">
                        <label class="am-checkbox-inline">
                        <input type="radio" value="1" v-model="goods.status" data-am-ucheck=""
                                   class="am-ucheck-radio">
                            <span class="am-ucheck-icons"><i class="am-icon-unchecked"></i><i
                                        class="am-icon-checked"></i></span>上架
                        </label>
                        <label class="am-checkbox-inline">
                        <input type="radio" value="2" v-model="goods.status" data-am-ucheck=""
                                   class="am-ucheck-radio">
                            <span class="am-ucheck-icons"><i class="am-icon-unchecked"></i><i
                                        class="am-icon-checked"></i></span>下架
                        </label>
                    </div>
                </div>
                <div class="am-form-group am-cf" v-show="goods.cid == 3">
                    <div class="zuo">主推：</div>
                    <div class="you" style="margin-top: 3px;">
                        <label class="am-checkbox-inline">
                            <input type="radio" value="1" v-model="goods.is_brand" data-am-ucheck=""
                                   class="am-ucheck-radio">
                            <span class="am-ucheck-icons"><i class="am-icon-unchecked"></i><i
                                        class="am-icon-checked"></i></span>是
                        </label>
                        <label class="am-checkbox-inline">
                            <input type="radio" value="0" v-model="goods.is_brand" data-am-ucheck=""
                                   class="am-ucheck-radio">
                            <span class="am-ucheck-icons"><i class="am-icon-unchecked"></i><i
                                        class="am-icon-checked"></i></span>否
                        </label>
                    </div>
                </div>
                <div class="am-form-group am-cf"  v-show="goods.cid == 7">
                    <div class="zuo">配送方式：</div>
                    <div class="you" style="margin-top: 3px;">
                        <label class="am-checkbox-inline">
                            <input type="radio" value="1" v-model="goods.is_gift" data-am-ucheck=""
                                   class="am-ucheck-radio">
                            <span class="am-ucheck-icons"><i class="am-icon-unchecked"></i><i
                                        class="am-icon-checked"></i></span>包邮
                        </label>
                        <label class="am-checkbox-inline">
                            <input type="radio" value="0" v-model="goods.is_gift" data-am-ucheck=""
                                   class="am-ucheck-radio">
                            <span class="am-ucheck-icons"><i class="am-icon-unchecked"></i><i
                                        class="am-icon-checked"></i></span>自提
                        </label>
                    </div>
                </div>

                <div class="am-form-group am-cf">
                    <div class="zuo">商品图片(183*183)：</div>
                    <div class="you">
                        <button type="button" class="layui-btn" id="test2">上传图片</button>
                        <div class="layui-upload-list " v-show="photo_old != ''">
                            <div class='del upImgs'>
                                <!-- <img class="layui-upload-img" id="demo1" src="http://qiniu.baoliy168.com/7be48506c0b3b71eb3bfdfaa53faccb5.jpg"> -->
                                <img class="layui-upload-img" id="demo1" :src="goods.goods_thumb">
                                <!-- <i class="fa fa-close closed"  v-on:click="del_one(photo_old)"></i> -->
                            </div>
                        </div>
                    </div>
                </div>
				  
				  <div class="am-form-group am-cf">
				      <div class="zuo">轮播图(长414*宽300)</div>
				      <div class="you">
				          <button type="button" class="layui-btn" id="uploads">轮播图上传</button>
				          <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
				              预览图：
				              <div class="layui-upload-list" id="demo3">
				                  <!-- <img v-for="val,index in goodsImgName" :src="val"  alt="" class="layui-upload-img" v-on:click="del(index)"> -->
				                  <div class="del" v-for="(val,index) in goodsImgName">
									  <div class="imgs">
										  <img :src=" val "  alt="" class="layui-upload-img updsa-imgs">
										  <i class="fa fa-close closed"  v-on:click="del(index)"></i>
									  </div>
				                  </div>
				              </div>
				          </blockquote>
				      </div>
				  </div>
				  
				<div id="pickfiles"></div>
                {{--<div class="am-form-group am-cf">--}}
                    {{--<div class="zuo">商品描述：</div>--}}
                    {{--<div class="you" style="max-width: 300px;">--}}
                        {{--<textarea class="" v-model="goods.spec" rows="2" id="doc-ta-1"></textarea>--}}
                    {{--</div>--}}
                {{--</div>--}}
                <div class="am-form-group am-cf">
                   <div class="zuo">商品详情</div>
                    <div class="you">
                        <textarea id="editor" v-model="goods.spec"></textarea>
                    </div>
                </div>
                <div class="am-form-group am-cf">
                    <div class="you" style="margin-left: 11%;">
                    <button type="button" class="am-btn am-btn-success am-radius"
                                v-on:click="add()">确定
                        </button>&nbsp;
                        <button type="button" class="am-btn am-btn-secondary am-radius"
                                onclick="javascript:history.back(-1);">返回
                        </button>
                    </div>
                </div>
            </form>
        </div>
		
		<script src="{{ URL::asset('js/admin/plupload.full.min.js') }}" charset="utf-8"></script>
		<script src="{{ URL::asset('js/admin/qiniu.js') }}" charset="utf-8"></script>
		
		
        <script src="{{ URL::asset('js/ueditor/ueditor.config.js') }}"></script>
        <script src="{{ URL::asset('js/ueditor/ueditor.all.min.js') }}"></script>
        <script src="{{ URL::asset('js/admin/amazeui.min.js') }}"></script>
        <script src="{{ URL::asset('js/admin/layui/layui.js') }}"></script>
        <script>
            function getContent() {
                var html = UE.getEditor('editor').getContent();
                return html;
            };
            window.onload = getContent;
        </script>

        <script>
			
			// console.log('{{csrf_token()}}');
			
            layui.use('laydate', function () {
                var laydate = layui.laydate;

                //执行一个laydate实例
                laydate.render({
                    elem: '#test1',
                    type: 'datetime',
                    format: 'yyyy/MM/dd HH:mm:ss',
                    show: false,
                    done: function (value, date, endDate) {
                        // console.log(value)
                        app.goods.startTime = value
                    }
                });
            });

            layui.use(['form', 'upload'], function () {
                var form = layui.form,
                    upload = layui.upload;
				// console.log();
				//普通图片上传
				var uploadInst = upload.render({
				      elem: '#test2' //绑定元素
				      ,url: '/upload?_token='+'{{csrf_token()}}'//上传接口
				      ,done: function(res){
							console.log(res)
				          if (res.code) {
				              app.del_one(app.photo_old)
				              app.photo_old = res.data;
				              app.getImg(res.data);
				          } else {
				              layer.msg(res.data);
				          }
				      }
				      ,error: function(err){
				          //请求异常回调
				          layer.msg('格式错误');
				      }
				  });
				  // 商品相册上传
				  upload.render({
				      elem: '#uploads'
				      ,url: '/upload?_token='+'{{csrf_token()}}' //上传接口
				      ,multiple: true
				      ,done: function(res){
				          console.log(res);
				          if (res.code) {
				              // console.log(res.data)
				              app.goodsImgName_old.push( res.data )
				              app.getImgs(res.data);
				          } else {
				              layer.msg(res.data);
				          }
				      }
				      ,error: function(err){
				          //请求异常回调
				          layer.msg('格式错误');
				      }
				  });
				
				
            });


            function two_tid(e)
            {
                app.goods.two_tid = '';
                $.post("/admin/classify/classify",{ '_token':'{{csrf_token()}}',class:'two_tid',cid:e },function (res) {
					console.log(res);
                    if(res.code){
                        $("#two_cid_li").show();
                        app.categoryLists = res.data
                    } else {
                        $("#two_cid_li").hide();
                        //layer.msg(res.data);
                    }
                });

            }


        </script>
        <script>
            var app = new Vue({
                el: '#app',
                data: {
                    goods: { //添加分类列表
						level:1,
                        id: '',
                        cid: '',
                        two_tid: '', //商品二级分类
                        goodsname: '',
                        status: '1',
                        is_gift: '1',
                        is_explosive: '',
                        is_brand: '0',
                        is_source: '0',
                        number: '',
                        originalprice: '',
                        costprice: '',
                        // memberprice: '',
                        rulingprice: '',
                        freight: '',
                        total: '',
                        sold: '',
                        sorting: '',
                        totalcnf: '0',
                        spec: '',//详情
                        sort: '',
                        straight: '',
                        weight: '',
                        timeprice: [''],
                        startTime: '',
                        purchase_num: '',
						goods_thumb:'',//商品封面
						rotation_chart:'',//轮播图
						goods_type:'',//商品类型
                        read_integral:'',//商品类型
                        is_throw:'0',//商品类型
                    },
                    //商品分类
                    categoryList: {},
					memberLevel:{},
					categoryLists: {},
                    //商品图片
                    goodsImgName: [],
					goodsImgName_old: [],
					photo_old: '',//旧图片
                },
                methods: {
                    addTimePrice: function () {
                        this.goods.timeprice.push('')
                    },
                    deTimePrice: function () {
                        this.goods.timeprice.splice(this.goods.timeprice.length - 1, 1)
                    },
                    two_tid: function (e) {
                        // console.log(e)
                        app.goods.two_tid = '';
                        $.post("/admin/classify/classify", {
                            '_token': '{{csrf_token()}}',
                            class: 'two_tid',
                            cid: e
                        }, function (res) {
							console.log(res);
                            if (res.code) {
                                $("#two_cid_li").show();
                                app.categoryLists = res.data
                            } else {
                                $("#two_cid_li").hide();
                                //layer.msg(res.data);
                            }
                        })
                    },
                    obtain: function (val) {
                        var query = window.location.search.substring(1);
                        var vars = query.split("&");
                        for (var i = 0; i < vars.length; i++) {
                            var pair = vars[i].split("=");
                            if (pair[0] == val) {
                                return pair[1];
                            }
                        }
                    },
                    initialize: function () {
                        var id = this.obtain('id');
						console.log(id);
                        if (id > 0) {
                            $.post("/admin/classify/goods", {
                                '_token': '{{csrf_token()}}',
                                class: 'find',
                                id: id
                            }, function (res) {
								console.log(res);
								// console.log(res.data.goods.rotation_chart);
								// console.log(app.goodsImgName);
                                if (res.code) {
                                    app.goods = res.data.goods;
                                    app.categoryList = res.data.cids;
                                    app.categoryLists = res.data.two_tids;
                                    app.goods.timeprice = JSON.parse(app.goods.timeprice);
									app.goods_thumb = res.data.goods.goods_thumb;
									// app.photo_old = app.goods_thumb.concat();
									app.goodsImgName = app.goods.rotation_chart;
									app.goodsImgName_old = app.goodsImgName.concat();
									// console.log(app.goods_thumb);
									app.photo_old = app.goods_thumb.split('com/')[1];
									// console.log(app.photo_old);
									console.log(res.data.goods.spec);
                                    UE.getEditor('editor').ready(function () {
                                        //this是当前创建的编辑器实例
                                        this.setContent(res.data.goods.spec);
                                    });
                                    // for (var i = 0; i < res.data.goodsImgName.length; ++i) {
                                    //     app.goodsImgName.push(res.data.goodsImgName[i].img);
                                    // }
									
                                    // $('.content-img-list').html("");
									// for (var a = 0; a < app.goods.rotation_chart.length; a++) {
										
									// }
                                    // for (var a = 0; a < app.goods.rotation_chart.length; a++) {
                                    //     // imgSrc.push(app.goods.rotation_chart[a]);
                                    //     var oldBox = $('.content-img-list').html();
                                    //     $(".content-img-list").html(oldBox + '<li class="content-img-list-item"><img src="' + app.goods.rotation_chart[a] + '" alt="">' +
                                    //         '<div class="hide"><a index="' + a + '" class="delete-btn"><i class="gcl gcllajitong">删除</i></a>' +
                                    //         '<a index="' + a + '" class="big-btn" type="button" data-toggle="modal" data-target=".bs-example-modal-lg"><i class="gcl gclfangda"></i></a></div></li>');
                                    // }
                                } else {
                                    layer.msg(res.data);
                                }
                            });
                        }
                        $.post("/admin/classify/classify", {
                            '_token': '{{csrf_token()}}',
                            class: 'select_cid'
                        }, function (res) {
                            if (res.code) {
                                app.categoryList = res.data
                            } else {
                                //layer.msg(res.data);
                            }
                        });
						$.post("/admin/classify/goods", {
						    '_token': '{{csrf_token()}}',
						    class: 'memberLevel'
						}, function (res) {
						    if (res.code) {
						        app.memberLevel = res.data
						    } else {
						        layer.msg(res.data);
						    }
						});
                    },
                    //编辑
                    edit: function (val) {
                        app.category = val;
						console.log(val);
                    },
                    // addDataAjax: function(){
                    //     app.goods.spec=getContent();
                    //     $.post("/admin/classify/goods", {
                    //         '_token': '{{csrf_token()}}',
                    //         class: 'add',
                    //         goods: app.goods,
                    //         goodsImgName: app.goodsImgName
                    //     }, function (res) {
                    //         if (res.code) {
                    //             layer.msg(res.data, {
                    //                 time: 600
                    //             }, function () {
                    //                 window.location.href = "/admin/classify/shop";
                    //             }, 500);
                    //         } else {
                    //             layer.msg(res.data);
                    //         }
                    //     });
                    // },
                    //添加商品
                    // add: function () {
                    //     var _this=this
                    //     // FormData上传图片
                    //     var formFile = new FormData();
                    //     $.each(imgFile, function (i, file) {
                    //         formFile.append('myFile[]', file);
                    //     });
                    //     formFile.append('_token','{{csrf_token()}}')
                    //     formFile.append('class','add')
                    //     formFile.append('imgType',true)
                    //     formFile.append('goodsId',app.goods.id)
                    //     $.ajax({
                    //         url: '/admin/classify/goods',
                    //         type: 'POST',
                    //         data: formFile,
                    //         async: true,
                    //         cache: false,
                    //         contentType: false,
                    //         processData: false,
                    //         dataType:'json',
                    //         success: function(res) {
                    //             if(res.code == 1){
                    //                 console.log(11)
                    //                 app.goods.rotation_chart=res.data
                    //                 _this.addDataAjax();
                    //             }
                    //         }
                    //     });
                    // },
                    //删除
					
					// 获取uptoken(上传凭证)和domain(bucket域名)
					getTokenMessage: function (uptoken, domain) {
					    var _this = this;
					    $.get("/getToken",function (res) {
					        // console.log(res);
					        _this.initQiniu(res.uptoken,res.domain);
					    });
					},
					initQiniu:function (uptoken,domain) {
					    Qiniu.uploader({
					        runtimes: 'html5,flash,html4',      // 上传模式，依次退化(照着官网来就是了)
					        // browse_button: 'pickfiles',         // 上传选择的点选按钮，必需(记得定义id并且保持一致)
							browse_button: 'pickfiles', 
					        // 在初始化时，uptoken，uptoken_url，uptoken_func三个参数中必须有一个被设置
					        // 切如果提供了多个，其优先级为uptoken > uptoken_url > uptoken_func
					        // 其中uptoken是直接提供上传凭证，uptoken_url是提供了获取上传凭证的地址，如果需要定制获取uptoken的过程则可以设置uptoken_func
					        uptoken : uptoken, // uptoken是上传凭证，由其他程序生成
					        // uptoken_url: '/getToken',         // Ajax请求uptoken的Url，强烈建议设置（服务端提供）
					        // uptoken_func: function(){        // 在需要获取uptoken时，该方法会被调用
					        //     // do something(一般是发送手动发送ajax获取到token，如果后端返回格式不跟官方一致又不想该懂源代码可以通过这个方式调整)
					        //     return uptoken;
					        // },
					        get_new_uptoken: false,             // 设置上传文件的时候是否每次都重新获取新的uptoken(没有特殊需求一般为false)
					        domain: domain,     // bucket域名，下载资源时用到，必需(找后端拿)
					        max_file_size: '3000mb',             // 最大文件体积限制(可以调大)
					        flash_swf_url: 'https://cdn.bootcss.com/plupload/2.1.1/Moxie.swf',  //引入flash，相对路径(如果没用到flash上传的话可以不设置,一般支持html5上传的浏览器都不会用到它)
					        max_retries: 3,                     // 上传失败最大重试次数(自动帮你续传分片)
					        chunk_size: '4mb',                  // 分块上传时，每块的体积
					        auto_start: true,    
							filters: {
							  mime_types : [
								{title : "Image files", extensions: "jpg,jpeg,gif,png"}
							  ]
							},
					        unique_names: false ,              //true生成唯一的文件名称
					        save_key: false,               // 选择文件后自动上传，若关闭需要自己绑定事件触发上传
					        init: {
					            FilesAdded: function(up, files) {
					                // console.log('文件就绪', files);
					            },
					            BeforeUpload: function(up, file) {
					                // console.log('上传之前', file);
					            },
					            UploadProgress: function(up, file) {
					                // console.log('上传中 file',file.percent);
					                // this.progress = file.percent + '%';
					                // $("#uploadBanner").text('视频已上传：' + file.percent + '%');
					            },
					            FileUploaded: function(up, file, info) {
					                // console.log('文件上传完毕')
					                // console.log(info)
					                var res=JSON.parse(info)
					                // console.log(file)
					                // console.log(res.key)
					                // app.goods.video=domain + res.key
					                // this.getVideo(res.key)
					            },
					            Error: function(up, err, errTip){
					                console.log('上传失败', err);
					            },
					            Key: function(up, file) {
					                //当save_key和unique_names设为false时，该方法将被调用
					                var key = "";
					                var ext = Qiniu.getFileExtension(file.name);
									
					                // console.log(ext);
					                var date = new Date();
					                var year = date.getFullYear();
					                var month = date.getMonth()+1;
					                var day = date.getDate();
					                var hour = date.getHours();
					                var minute = date.getMinutes();
					                var second = date.getSeconds();
					                key += ''+year+month+day+hour+minute+second;
					                key += '.' + ext;
					                return key;
					                // console.log(key);
					            }
					        }
					    });
					},
					// 上传图片
					getImg:function( key ){
					    if(key!=""){
					        $.post("/getFile", {'_token': '{{csrf_token()}}',key: key},function (res) {  
								console.log(res);
					            app.goods.goods_thumb = res;   
					        });
					    }
					},
					getImgs:function( key ){
					
					    if(key!=""){
					        $.post("/getFile", {'_token': '{{csrf_token()}}',key:key},function (res) {        
								// console.log(res);
					            app.goodsImgName.push( res ); 
					            // console.log(app.goodsImgName)
					        });
					    }
					},
					del_one:function (old) {
					    if(old != ""){
					        $.post("/delete", {'_token': '{{csrf_token()}}',key:old},function (res) {
								console.log(res);
					            if(res.code){
					                // layui.use('layer', function(){
					                //     var layer = layui.layer;
					                //     layer.msg(res.data)
					                // });
					                // app.photo_old='';
									
					            } else {
					                layui.use('layer', function(){
					                    var layer = layui.layer;
					                    layer.msg(res.data)
					                });
					            }
					        });
					
					    }
					},
					//删除轮播图
					del:function (index) {
					    var _this=this;
					    var old=app.goodsImgName_old[index];
					    app.goodsImgName.splice(index,1);
					    app.goodsImgName_old.splice(index,1);
					    _this.del_one(old);
					},
					//添加
					save: function () {
					    $.post("/admin/classify/classify", {
					        '_token': '{{csrf_token()}}',
					        class: 'add',
					        category: app.category
					    }, function (res) {
					        if (res.code) {
					            layer.msg(res.data);
					            window.location.href = "/admin/classify/shopClass";
					        } else {
					            layer.msg(res.data);
					        }
					    });
					},
					add:function(){
					    app.goods.spec = getContent();
					    app.goods.rotation_chart = app.goodsImgName;
					    if(this.goods.rotation_chart==''){
					        layer.msg('请上传商品轮播图')
					        return false
					    }
						//
					    console.log(app.goods);
					    $.post("/admin/classify/goods", {'_token': '{{csrf_token()}}',class: 'add',goods:app.goods},function (res) {     
							console.log(res);
					        if(res.code == 1){
					            layui.use('layer', function(){
					                var layer = layui.layer;
									layer.msg("设置成功", {icon: 6},function () {
									    window.location.href = "/admin/classify/shop";
									});
					//                 layer.msg(res.data, {icon: 6},function () {
					//                     //关闭当前frame
					//                     x_admin_close();
					
					//                     // 可以对父窗口进行刷新 
					//                     x_admin_father_reload();
					//                 });
					            });
					        }else{
								layer.msg(res.data);
					            // layui.use('layer', function(){
					            //     var layer = layui.layer;
					            //     layer.msg(res.data)
					            // });
					        }   
					    });
					},
					// empty: function () {
					//     app.category = {
					//         id: '',
					//         pid: '',
					//         thumb: '',
					//         image: '',
					//     };
					// },
                },
                //自动执行
                mounted: function () {
					var _this = this;
                    _this.initialize();
					_this.getTokenMessage();
					// console.log(app.photo_old)
                },
            })

        </script>
		<script>
			
			
		</script>
@include('Admin.public.foot')